<template>
  <div class="mainBox">
    <div
      :class="['tag', activate ? 'activate' : '']"
      @click="changeActivate(true)"
    >
      行业奖项
      <span v-if="activate" class="triangle"></span>
    </div>
    <div
      :class="['tag', activate ? '' : 'activate']"
      @click="changeActivate(false)"
    >
      政府表彰
      <span v-if="!activate" class="triangle"></span>
    </div>
    <div class="content">
      <!-- 荣誉列表 -->
      <div class="award-list">
        <div class="award-item" v-for="(item, index) in honorList" :key="index">
          <div class="award-left">
            <img
              :src="
                activate
                  ? require('@/assets/images/industry.png')
                  : require('@/assets/images/redindustry.png')
              "
              class="award-icon"
              alt="奖项"
            />
            <div class="award-info">
              <span class="award-name">{{ item.honorName }}</span>
              <span class="award-level">{{ item.honorLevel }}</span>
            </div>
          </div>
          <span class="award-attachment" @click="viewAttachment(item)"
            >查看附件</span
          >
        </div>
      </div>

      <!-- 空状态 -->
      <div v-if="!honorList || honorList.length === 0" class="empty-state">
        <van-empty description="暂无数据" />
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "honerIndustry",
  props: {
    honorList: {
      type: Array,
      default: () => [],
    },
    controlId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      activate: true,
    };
  },
  methods: {
    changeActivate(val) {
      this.activate = val;
      // 切换标签时，通知父组件重新获取数据
      const honorType = val ? "1" : "2"; // true:行业奖项(1), false:政府表彰(2)
      this.$emit("changeHonorType", honorType);
    },
    viewAttachment(item) {
      console.log("查看附件", item);
      if (item.honorAddress) {
        // 如果有附件地址，打开链接
        window.open(item.honorAddress, "_blank");
      } else {
        this.$toast("暂无附件");
      }
    },
  },
};
</script>
<style lang="less" scoped>
.mainBox {
  font-family:
    PingFangSC,
    PingFang SC;
  padding: 15px;
  background-color: #f5f5f5;
  min-height: 100%;
  .tag {
    display: inline-block;
    position: relative;
    width: 84px;
    height: 30px;
    border-radius: 4px;
    line-height: 30px;
    text-align: center;
    margin-right: 10px;
    font-size: 14px;
    color: #999;
    background-color: #fbfbfe;
  }
  .activate {
    color: #333;
    background-color: #fff;
  }
  .triangle {
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid #fff;
  }

  .content {
    margin-top: 16px;

    .award-list {
      .award-item {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px;
        padding-left: 30px;
        background: #fff;
        border-radius: 8px;
        margin-bottom: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);

        &:last-child {
          margin-bottom: 0;
        }

        .award-left {
          display: flex;
          align-items: center;
          flex: 1;

          .award-icon {
            position: absolute;
            left: 0;
            top: 0;
            height: 40px;
            flex-shrink: 0;
          }

          .award-info {
            display: flex;
            align-items: center;
            flex: 1;

            .award-name {
              font-size: 14px;
              color: #333;
              margin-right: 8px;
            }

            .award-level {
              font-size: 12px;
              padding: 2px 8px;
              border-radius: 4px;
              border: 1px solid;
              flex-shrink: 0;
              color: #1890ff;
              background-color: #e6f7ff;
              border-color: #91d5ff;
            }
          }
        }

        .award-attachment {
          font-size: 14px;
          color: #1890ff;
          cursor: pointer;
          flex-shrink: 0;
          margin-left: 12px;

          &:hover {
            color: #40a9ff;
          }
        }
      }
    }
  }

  .empty-state {
    padding: 40px 0;
    text-align: center;
  }
}
</style>
